<!--
 * @Author: Rain
 * @Date: 2023/10/07 10:35:15
 * @LastEditTime: 2023/11/17 22:00:16
 * @Description: Do Something
-->
<template>
  <div class="app-container w-full h-full overflow-hidden">
    <!--工具栏-->
    <div class="head-container w-full overflow-hidden flex flex-col h-full">
      <div class="flex items-center search pb-10 justify-end">
        <el-input
          v-model="query.courseName"
          clearable
          placeholder="课程名称"
          style="width: 185px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-select v-model="query.platform" placeholder="课程类型" clearable>
          <el-option
            v-for="item in [
              { label: '线上', value: 0 },
              { label: '线下', value: 1 },
            ]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>

        <el-date-picker
          v-model="query.updatetTime"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
        <rrOperation :crud="crud" />
      </div>
      <div class="flex-1 w-full overflow-hidden">
        <el-table
          ref="table"
          v-loading="crud.loading"
          :data="crud.data"
          size="small"
          style="width: 100%"
          height="100%"
          @selection-change="crud.selectionChangeHandler"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column prop="courseName" label="名称" />
          <el-table-column prop="courseNo" label="课程类型">
            <template slot-scope="scope">{{
              dict.label.course_type[scope.row.platform]
            }}</template>
          </el-table-column>
          <el-table-column prop="sellPrice" label="原价(元)" />
          <el-table-column prop="discountPrice" label="优惠价格(元)" />
          <el-table-column prop="openTime" label="开班时间" />
          <el-table-column prop="updateTime" label="发布时间" />
          <el-table-column prop="payStatus" label="报名人数(人)">
            <template slot-scope="scope">
              <span>{{ scope.row?.orderDTO?.enrollNum }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="orderStatus" label="收费总金额(元)">
            <template slot-scope="scope">
              <span>{{ scope.row?.orderDTO?.payTotalAmount }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="150px" align="center">
            <template slot-scope="{ row }">
              <el-button
                type="primary"
                size="small"
                @click="viewPeople(row)"
              >查看报名人员</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <pagination />
    </div>
    <el-dialog
      :close-on-click-modal="false"
      :visible.sync="showDialog"
      title="报名人员"
      width="500px"
    >
      <el-table :data="peopleList" style="width: 100%">
        <el-table-column header-align="center" align="center" prop="name" label="姓名" />
        <el-table-column
          header-align="center"
          align="center"
          prop="mobile"
          label="电话"
        />
        <el-table-column header-align="center" align="center" prop="city" label="地址" />
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="default" @click="showDialog = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import crudCourseOrder from '@/api/courseOrder'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import pagination from '@crud/Pagination'

const defaultForm = {
  orderId: null,
  orderNo: null,
  courseNo: null,
  orderAmount: null,
  payAmount: null,
  openId: null,
  prePayid: null,
  paySerialid: null,
  payStatus: null,
  orderStatus: null,
  updateTime: null,
  createTime: null,
  failMsg: null,
  remark: null
}

export default {
  name: 'CourseOrder',
  components: { pagination, rrOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['course_type'],
  cruds() {
    return CRUD({
      title: '课程订单',
      url: 'api/courseOrder',
      idField: '',
      sort: 'desc',
      crudMethod: { ...crudCourseOrder },
      optShow: {
        add: false,
        del: false,
        reset: true,
        upload: false
      }
    })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'courseOrder:add'],
        edit: ['admin', 'courseOrder:edit'],
        del: ['admin', 'courseOrder:del']
      },
      rules: {},
      queryTypeOptions: [
        { key: 'courseName', display_name: '课程名称' },
        { key: 'platform', display_name: '课程类型' },
        { key: 'updateTime', display_name: '发布时间' }
      ],
      showDialog: false,
      peopleList: []
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    viewPeople(row) {
      this.userList = []
      const {
        orderDTO: { userList }
      } = row
      this.peopleList = userList
      this.showDialog = true
    }
  }
}
</script>

<style scoped></style>
